<template>
  <div class="app-container">
    <uc-table url="admin/inspect/list" name="用户" ref="userTable" pageable table-border :search-form="searchForm"
              @selection-change="handleSelectionChange">
      <template slot="searchForm">
        <el-form size="mini" :inline="true" :model="searchForm" class="demo-form-inline filter-container">
          <!--搜索输入框-->
          <el-form-item>
            <el-input type="text" v-model="searchForm.title" placeholder="请输入任务名称" clearable
                      @clear="clearInput()"></el-input>
          </el-form-item>
          <el-form-item v-if="enterPriseHidden">
            <el-select v-model="searchForm.inspectEnterpriseId" placeholder="请选择业主单位" style="width: 100%" clearable
                       @clear="clearInput1()">
              <el-option v-for="(item,index) in enterpriseDominantList" :key="index" :value="item.ucId"
                         :label="item.name"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-select v-model="searchForm.status" placeholder="请选择状态" style="width: 100%" clearable>
              <el-option
                  v-for="dict in inspectStatus"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
              />
            </el-select>
          </el-form-item>
          <!--搜索按钮--新增按钮-->
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" class="filter-item" @click="handleSearch()">查询</el-button>
            <el-button type="success" icon="el-icon-plus" class="filter-item" @click="handleAdd()">新 增</el-button>
          </el-form-item>
        </el-form>
      </template>
      <template slot="columns">
        <el-table-column type="selection" width="55" align="center"/>
        <el-table-column prop="title" label="任务名称" align="left" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="inspectEnterpriseName" label="业务企业" align="left" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="inspectPersonName" label="检查人员" align="left" :show-overflow-tooltip="true"> </el-table-column>
        <el-table-column prop="status" label="状态" align="left">
          <template slot-scope="scope">
            {{ statusFormat(scope.row.status)}}
          </template>
        </el-table-column>
        <el-table-column prop="address" label="操作" width="220" align="left" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <!--编辑按钮-->
            <el-button size="mini" icon="el-icon-edit" type="primary" @click="handleEdit(scope.row)">编辑</el-button>
            <el-button size="mini" icon="el-icon-info" type="success" @click="handleInfo(scope.row)">详情</el-button>
            <el-button size="mini" type="danger" icon="el-icon-delete" @click="handleDelete(scope.row)">删除
            </el-button>
          </template>
        </el-table-column>
      </template>
    </uc-table>
  </div>
</template>
<script>
import UcTable from "@/components/UcTable/index.vue";
import {deleteInUser, updateInUser, getInEnterpriseList, exportInUser} from "@/api/enterprise";
import {getInEnterpriseYZList} from "@/api/enterpriseDominant";

export default {
  name: "userList",
  components: {UcTable},
  data() {
    return {
      searchForm: {
        title: "",
        inspectEnterpriseId: "",
        status: ""
      },
      ids: [],
      inspectStatus: [],
      //选中岗位编码数组
      enterpriseDominantList: []
    }
  },
  computed: {
    enterPriseHidden() {
      let roleCode = this.$store.getters.roleCode;
      return roleCode == "ADMIN" || roleCode == "XT-ADMIN" || roleCode == "ZD-ADMIN" || roleCode == "DD-ADMIN" || roleCode == "JW-ADMIN"
    }
  },
  created() {
    this.getDicts("inspect_status").then(response => {
      this.inspectStatus = response.data.data;
    });
    this.getInEnterpriseYZList()
  },
  methods: {
    // 状态字典翻译
    statusFormat(data) {
      return this.selectDictLabel(this.inspectStatus, data);
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
    },
    handleSearch() {
      this.$refs.userTable.getTableData(1)
    },
    handleAdd() {
      this.$router.push("/inspect/edit/0")
    },
    handleEdit(val) {
      this.$router.push("/inspect/edit/" + val.ucId)
    },
    handleInfo(val) {
      this.$router.push("/inspect/info/" + val.ucId)
    },
    clearInput() {
      //清除输入框
      this.searchForm.name = null
      this.handleSearch()
    },
    clearInput1() {
      //清除输入框
      this.searchForm.flagId = null
      this.handleSearch()
    },
    handleDelete(val) {
      this.$confirm('您确定要执行删除' + val.userName + '这个用户吗？', '提醒信息', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.deleteLoading = true
        deleteInUser(val).then(res => {
          this.deleteLoading = false
          this.$notify.success({
            title: '成功',
            message: "删除用户成功"
          })
          this.handleSearch()
        }).catch(res => {
          this.deleteLoading = false
          this.$notify.error({
            title: '失败',
            message: res.msg
          })
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    getInEnterpriseYZList() {
      getInEnterpriseYZList({deleted: false}).then(res => {
        this.enterpriseDominantList = res.data
      }).catch(error => {

      })
    }
  }
}
</script>

<style scoped>

</style>
